<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.min.css" rel="stylesheet" />
		<link href="css/article_style.css" rel="stylesheet" />
	</head>

	<body>
		<!--头部-->
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left "></a>
			<h1 class="mui-title">文章</h1>
		</header>
		
		<!--内容-->
		<div class="mui-content" id="article"></div>
		
		
		<!--引用的 JS-->
		<script src="js/mui.min.js"></script>
		<script src="js/template-web.js"></script>
			
		<!--HTML模板-->
		<script id="article-template" type="text/html">
			<div style="padding: 10px;">
		    	<h2>{{item.title}}</h2>
				<div class="article-mid-title">
					<span class="item item-pubdate" id="pubdate">
						日期：{{item.pubdate}}
					</span>					 	
					
					<span class="item item-category">
						类别：{{item.category}}	
					</span>
						
			  	</div>
				<div class="article-content">
					{{@item.content}}
	  			</div>
	  			<div>
	  				<button id="votebtn" type="button" class="mui-btn-red mui-btn-block mui-btn-outlined" >
	  					点赞：{{item.upvote}}
	  				</button>
	  				<button type="button" class="mui-btn-green mui-btn-block mui-btn-outlined">
	  					阅读量：{{item.read}}
	  				</button>
	  				<button type="button" class="mui-btn-blue mui-btn-block mui-btn-outlined">
	  					<a href="{{item.publisher_src}}" style="color:#666;">查看来源：{{item.publisher}}</a>
	  				</button>
	  				
			  		
	  			</div>
	  			
			</div>
		</script>
		
		<!--JS代码-->
		<script type="text/javascript">
			mui.init()
			window.addEventListener('currentId',function(e){
				// 获得参数
				var id = e.detail.id;


				
				// 根据 id 请求文章详情
				mui.getJSON('http://ihealth.yangyingming.com/api/v1/article?id=' + id, function(data){
					// 根据模板将数据渲染成 HTML
					var html = template('article-template', {'item':data});
					// 将 HTML 插入到页面中
					document.getElementById('article').innerHTML = html;
					// 优化 img 标签显示效果
					var articleElement = document.getElementById('article');
					var imgs = articleElement.getElementsByTagName('img');
					for(var i = 0; i < imgs.length; i++){
						imgs[i].style = 'width:100%;';
					}
					//wd-增加alert
					//
					var votebtn = document.getElementById('votebtn');
					votebtn.addEventListener('tap',function(){
						mui.alert('感谢您的投票！', '提示', function() {
								votebtn.disabled=true;
							});
						
					})
					//wd
					
					//wd-日期更改
					//添加id
					var dateObj	=	document.getElementById('pubdate');
					var dateNum	=	dateObj.innerHTML;
					//mui.toast(dateNum.slice(0,20));
					dateObj.innerHTML=dateNum.slice(0,20);
					//-----wd
																									
//					 替换 h3 标签为 strong 标签
//					h3s = articleElement.getElementsByTagName('h3');
//					for(var i = h3s.length-1; i >=0 ; i--){
//						strongTag = document.createElement('strong');
//						strongTagChild = document.createElement('p');
//						strongTagChild.innerHTML = h3s[i].innerText;
//						strongTag.appendChild(strongTagChild);
//						h3s[i].parentNode.replaceChild(strongTag,h3s[i]);
//					}
				});
			});
			
			
		</script>
	</body>

</html>
